package S15.second;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class S01 {

	public static void main(String[] args) {
		String[] ps = { "zhangsan", "lisi", "wangwu", "lisi" };
		// (1)流中数据收集到 List
		System.out.println("流中数据收集到 List: ");
		List<String> list = Arrays.stream(ps).collect(Collectors.toList());
		// List<String> list = Stream.of(ps).collect(Collectors.toList());
		list.forEach(System.out::println);

		// (2)流中数据收集到 Set
		System.out.println("流中数据收集到 Set: ");
		Set<String> set = Stream.of(ps).collect(Collectors.toSet());
		set.forEach(System.out::println);
		// (3)流中数据收集到 HashSet
		System.out.println("流中数据收集到 HashSet:");
		HashSet<String> hashSet = Stream.of(ps).collect(Collectors.toCollection(() -> new HashSet<String>()));
		hashSet.forEach(System.out::println);
		// (4)流中数据收集到 LinkedHashSet
		System.out.println("流中数据收集到 LinkedHashSet:");
		LinkedHashSet<String> collect = Stream.of(ps).collect(Collectors.toCollection(LinkedHashSet<String>::new));
		collect.forEach(System.out::println);
		//(5)流中数据收集到 ArrayList
		System.out.println("流中数据收集到 ArrayList:");
		ArrayList<String> arrayList = Stream.of(ps).collect(Collectors.toCollection(ArrayList::new));
		arrayList.forEach(System.out::println);
		//(6)流中数据收集到 Map
		System.out.println("流中数据收集到 Map:");
		Map<String,String> map = Stream.of(ps).distinct().collect(Collectors.toMap(s->s, s->s.toUpperCase()));
		map.forEach((k,v)->System.out.println(k+"  --->  "+v));

		Map<String, Integer> map2 = Stream.of(ps).distinct().collect(Collectors.toMap(s->s, s->s.length()));
		map2.forEach((k,v)->System.out.println(k+"  --->  "+v));
	}

}
